home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / grapdrvs / draw_srf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-04  |  4.7 KB  |  140 lines

  1. /*****************************************************************************
  2. *   Default surface drawing routine common to graphics drivers.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include "irit_sm.h"
  8. #include "iritprsr.h"
  9. #include "allocate.h"
  10. #include "attribut.h"
  11. #include "cagd_lib.h"
  12. #include "symb_lib.h"
  13. #include "ip_cnvrt.h"
  14. #include "iritgrap.h"
  15.  
  16. /*****************************************************************************
  17. * DESCRIPTION:                                                               M
  18. * Draw a single surface object using current modes and transformations.         M
  19. *   Piecewise linear approximation is cashed under "_isoline" and "_ctlmesh" M
  20. * attributes of PObj. Polygonal approximation is saved under "_polygons".    M
  21. *                                                                            *
  22. * PARAMETERS:                                                                M
  23. *   PObj:     A surface object to draw.                                      M
  24. *                                                                            *
  25. * RETURN VALUE:                                                              M
  26. *   void                                                                     M
  27. *                                                                            *
  28. * KEYWORDS:                                                                  M
  29. *   IGDrawSurface                                                            M
  30. *****************************************************************************/
  31. void IGDrawSurface(IPObjectStruct *PObj)
  32. {
  33.     IPObjectStruct *PObjPolylines, *PObjCtlMesh, *PObjPolygons;
  34.     IPPolygonStruct *PPolylines, *PCtlMesh, *PPolygons, *PPolygonTemp;
  35.  
  36.     if (IGGlblDrawSurfacePoly || IGGlblDrawSolid) {
  37.     if ((PObjPolygons = AttrGetObjectObjAttrib(PObj, "_polygons"))
  38.                                     == NULL) {
  39.         CagdSrfStruct *Srf,
  40.             *Srfs = PObj -> U.Srfs;
  41.  
  42.         PObjPolygons = IPAllocObject("", IP_OBJ_POLY, NULL);
  43.         PObjPolygons -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  44.         IP_SET_POLYGON_OBJ(PObjPolygons);
  45.  
  46.         for (Srf = Srfs; Srf != NULL; Srf = Srf -> Pnext) {
  47.         PPolygons = IritSurface2Polygons(Srf, IGGlblFourPerFlat,
  48.                          IGGlblFineNess, FALSE,
  49.                          IGGlblPolygonOptiApprox);
  50.  
  51.         if (PPolygons != NULL) {
  52.             if (PPolygons) {
  53.             for (PPolygonTemp = PPolygons;
  54.                  PPolygonTemp -> Pnext;
  55.                  PPolygonTemp = PPolygonTemp -> Pnext);
  56.             PPolygonTemp -> Pnext = PObjPolygons -> U.Pl;
  57.             PObjPolygons -> U.Pl = PPolygons;
  58.             }
  59.         }
  60.         }
  61.         if (IGGlblCacheGeom)
  62.         AttrSetObjectObjAttrib(PObj, "_polygons", PObjPolygons, FALSE);
  63.     }
  64.  
  65.         if (PObjPolygons != NULL) {
  66.         IGDrawPoly(PObjPolygons);
  67.  
  68.         if (!IGGlblCacheGeom)
  69.         IPFreeObject(PObjPolygons);
  70.     }
  71.     }
  72.     else {
  73.     if ((PObjPolylines = AttrGetObjectObjAttrib(PObj, "_isoline")) == NULL &&
  74.         IGGlblNumOfIsolines > 0) {
  75.         CagdSrfStruct *Srf,
  76.         *Srfs = PObj -> U.Srfs;
  77.  
  78.         PObjPolylines = IPAllocObject("", IP_OBJ_POLY, NULL);
  79.         PObjPolylines -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  80.         IP_SET_POLYLINE_OBJ(PObjPolylines);
  81.         for (Srf = Srfs; Srf != NULL; Srf = Srf -> Pnext) {
  82.         int NumOfIso[2];
  83.  
  84.         NumOfIso[0] = -IGGlblNumOfIsolines;
  85.         NumOfIso[1] = -IGGlblNumOfIsolines;
  86.         PPolylines = IritSurface2Polylines(Srf, NumOfIso,
  87.                            IGGlblSamplesPerCurve,
  88.                            IGGlblPolylineOptiApprox);
  89.  
  90.         if (PPolylines != NULL) {
  91.             for (PPolygonTemp = PPolylines;
  92.              PPolygonTemp -> Pnext;
  93.              PPolygonTemp = PPolygonTemp -> Pnext);
  94.             PPolygonTemp -> Pnext = PObjPolylines -> U.Pl;
  95.             PObjPolylines -> U.Pl = PPolylines;
  96.         }
  97.         }
  98.         if (IGGlblCacheGeom)
  99.         AttrSetObjectObjAttrib(PObj, "_isoline", PObjPolylines, FALSE);
  100.     }
  101.  
  102.         if (PObjPolylines != NULL) {
  103.         IGDrawPoly(PObjPolylines);
  104.  
  105.         if (!IGGlblCacheGeom)
  106.         IPFreeObject(PObjPolylines);
  107.     }
  108.     }
  109.  
  110.     if (IGGlblDrawSurfaceMesh) {
  111.     if ((PObjCtlMesh = AttrGetObjectObjAttrib(PObj, "_ctlmesh"))
  112.                                 == NULL) {
  113.         CagdSrfStruct *Srf,
  114.         *Srfs = PObj -> U.Srfs;
  115.  
  116.         PObjCtlMesh = IPAllocObject("", IP_OBJ_POLY, NULL);
  117.         PObjCtlMesh -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  118.         IP_SET_POLYLINE_OBJ(PObjCtlMesh);
  119.         for (Srf = Srfs; Srf != NULL; Srf = Srf -> Pnext) {
  120.         PCtlMesh = IritSurface2CtlMesh(Srf);
  121.  
  122.         for (PPolygonTemp = PCtlMesh;
  123.              PPolygonTemp -> Pnext;
  124.              PPolygonTemp = PPolygonTemp -> Pnext);
  125.         PPolygonTemp -> Pnext = PObjCtlMesh -> U.Pl;
  126.         PObjCtlMesh -> U.Pl = PCtlMesh;
  127.         }
  128.         if (IGGlblCacheGeom)
  129.         AttrSetObjectObjAttrib(PObj, "_ctlmesh", PObjCtlMesh, FALSE);
  130.     }
  131.  
  132.         if (PObjCtlMesh != NULL) {
  133.         IGDrawPoly(PObjCtlMesh);
  134.  
  135.         if (!IGGlblCacheGeom)
  136.         IPFreeObject(PObjCtlMesh);
  137.     }
  138.     }
  139. }
  140.